using System;
using System.Diagnostics;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using MCGameEngine.Physic_Layer;
using MCGameEngine.Sprite_Layer;
using MCGameEngine.Text_Layer;

namespace MCGameEngine
{
    public class Engine
    {
        private MyGame game;

        public Repository<Model> Models;
        public Repository<SpriteFont> SpriteFonts;
        public Repository<Texture2D> Textures2D;

        private AudioEngine audioengine;
        private SoundBank soundbank;
        private WaveBank wavebank;
        private AudioListener audiolistener;

        public PhysicObject Protagonist
        {
            get
            {
                return game.camera.Protagonist;
            }
            set
            {   
                game.camera.Protagonist = value;
            }
        
        }

        private bool gameready;

        public Engine()
        {
            game = new MyGame();
            game.Activated += new EventHandler(event_switcher);
            game.on_updating += new EventHandler(event_switcher);

            Models = new Repository<Model>(game.Content);
            SpriteFonts = new Repository<SpriteFont>(game.Content);
            Textures2D = new Repository<Texture2D>(game.Content);

            gameready = false;
         
       /*     audioengine = new AudioEngine("prova.xap");
            soundbank = new SoundBank(audioengine, "file");
            wavebank = new WaveBank(audioengine, "file");   */

            audiolistener = new AudioListener();
        }

        private void event_switcher(object o, EventArgs e)
        {
            string str = o.ToString();

            switch (str)
            {
                case "MCGameEngine.MyGame":
                    if (!gameready)
                    {
                        Loaded();
                    }
                    gameready = true;
                break;

                case "update":
                    if (gameready)
                    {
                        Update((UpdatingArgs)e);
                    }
                break;

                case "object_collision":
                    if (gameready)
                    {
                        ObjectCollision((CollisionArgs)e);
                    }
                break;
            }
        }

        public virtual void Update(UpdatingArgs args)
        {

        }

        public virtual void Loaded()
        {
        
        }

        public virtual void ObjectCollision(CollisionArgs args)
        {
        
        }

        public void Run()
        {
            game.Run();
        }

        #region ADD REGION

        public void Add(Label LBL)
        {
            game.Texts.Add(LBL);
        }

        public void Add(Label LBL, string name)
        {
            game.Texts.Add(LBL, name);
        }

        public void Add(BasicObject bo)
        {
            game.Physic.Add(bo);
        }
        public void Add(BasicObject bo, string name)
        {
            game.Physic.Add(bo, name);
        }

        public void Add(Sprite sp)
        {
            game.Sprites.Add(sp);
        }
        public void Add(Sprite sp, string name)
        {
            game.Sprites.Add(sp, name);
        }

        #endregion
    }
}
